package com.softer.chengxin.sysrole.dao.provider;

import com.softer.chengxin.common.domin.Page;
import com.softer.chengxin.sysrole.entity.Role;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;

/**
 * @author zcz
 * @date 2018/12/20
 */
public class SysRoleDaoProvider {
    /**
     * 查询企业从业人员信息数量
     *
     * @param map map
     * @return sql
     */
    public String getList(HashMap<String, Object> map) {
        StringBuffer sql = new StringBuffer(20);
        Page page = (Page) map.get("page");
        String loginName = (String) map.get("loginName");
        sql.append("SELECT id ,roles_name AS roleName,adder,ADDTIME AS addTime FROM roules WHERE adder='"+loginName+"' and role_type = '0'");
        sql.append(" LIMIT ");
        sql.append(page.getBeginIndex()).append(",").append(page.getLimit());
        return sql.toString();
    }
    /**
     * 修改角色信息
     * @param role
     * @return
     */
    public String update(Role role) {
        StringBuffer sql = new StringBuffer(20);
        sql.append("UPDATE roules SET addtime=NOW() ");
        commonSql(sql, role);
        System.out.println("修改sql:"+sql.toString());
        return sql.toString();
    }

    private void commonSql(StringBuffer sql, Role role) {
        if(StringUtils.isNotBlank(role.getRoleName())){
            sql.append(" ,roles_name=#{roleName} ");
        }
        if(StringUtils.isNotBlank(role.getModules())){
            sql.append(" ,mo_dules=#{modules} ");
        }
        sql.append(" where id=#{id}");
    }
}
